package org.example.vueadminapi2.controller;

import jakarta.annotation.Resource;
import org.example.vueadminapi2.dto.Result;
import org.example.vueadminapi2.entity.User;
import org.springframework.web.bind.annotation.*;
import org.example.vueadminapi2.service.UserService;

import java.util.Objects;

@CrossOrigin(maxAge = 3600)
@RestController
public class UserController {
/**
 * @FileName: UserController
 * @Description:
 * @Author: cyx
 * @date: 2025-02-24
 **/

    @Resource
    private UserService userService;

    @PostMapping(value="/login")
    public Result login(@RequestBody User user) {
        User user1 = userService.login(user);
        if (Objects.nonNull(user1)){
            return Result.ok(user1);
        }
        else return Result.error("用户名或密码错误");

    }

//    @PostMapping(value="/GetUserByToken")
//    public Result GetUserByToken(@RequestBody User user) {
//        User user1 = userService.GetUserByToken(user);
//        if (Objects.nonNull(user1)){
//            return Result.ok(user1);
//        }
//        else return Result.error("token不存在");
//
//    }
    @GetMapping(value="/GetUserByToken")
    public Result GetUserByToken(String token) {
        System.out.println(token);
        User user = userService.GetUserByToken(token);
        if (Objects.nonNull(user)){
            return Result.ok(user);
        }
        else return Result.error("token不存在");
    }

}
